<script> 
    var total_num = 0;
    var arr_pm_code = <?=json_encode($arr_pm_code);?>;
</script>
<div class="box-content">
    <?=form_open(uri_string(),array('id'=>'checknew'));?>
        <table width="100%">
            <tr>
                <td>    
                    <input type="hidden" name="group_id" value="<?php echo $rs->group_id;?>">
                    <table class="form"  style="margin:auto;width:50%">
                        <tr>
                            <td class="w150 required label"><?php echo lang('group.name');?></td>
                            <td><input type="text" name="group_name"  class="w150" value="<?php echo $rs->group_name; ?>"></td>
                        </tr>
                        <tr>
                            <td class="label"><?php echo lang('group.comment');?></td>
                            <td>
                                <textarea class ="w150" style="height: 50px;" name="group.comment"><?php echo $rs->group_comment;?></textarea>
                            </td>
                        </tr>        
                        <tr>
                            <td></td>
                            <td class="footer"><input type="submit" name="bt_submit" class="capnhat"></td>
                        </tr>               
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <h4><?php echo lang('group.check_all');?> <input type="checkbox" name="sa" id="sa" onclick="check_chose_right('sa', total_num, 'checknew')" /> <?php echo lang('admin.choose_all');?></h4>
                    <table class="admindata" width="100%">
                        <?php 
                            $k=1;
                            $i=0;
                            foreach($modules as $module){
                                $functions  = $this->group->get_all_function($module->module_id);
                        ?>
                            <tr class="row<?=$k?>">
                                <td>
                                    <div class="permission_name"><b><?=$module->module_name?></b> <?=($module->module_comment!='')?('['.$module->module_comment.']'):"";?></div>
                                    <div style="overflow: hidden;">
                                        <?php  
                                            foreach($functions as $func){
                                                $right =$this->group->get_right_gr_md_fc($rs->group_id,$module->module_id,$func->function_id); 
                                                if($right){
                                                    $right_pm = json_decode($right->permission,true);
                                                }else{
                                                    $right_pm=array();
                                                }
                                        ?>
                                            <input type="hidden" name="arr_right[<?=$i;?>][group_id]" value="<?php echo  $rs->group_id; ?>"/>
                                            <input type="hidden" name="arr_right[<?=$i;?>][module_id]" value="<?php echo $module->module_id; ?>"/>
                                            <input type="hidden" name="arr_right[<?=$i;?>][function_id]" value="<?php echo $func->function_id; ?>"/>
                                            <input type="hidden" name="arr_right[<?=$i;?>][right_id]" value="<?php echo isset($right->right_id)?$right->right_id:''; ?>"/>
                                            <br/>
                                            <div class="function_name"><input type="checkbox" name="fc_<?php echo $i;?>" id="fc_<?php echo $i;?>" onclick ="check_chose_function('fc_<?php echo $i;?>','<?php echo $i;?>','checknew')"><span><b><?php echo $func->function_name; ?></b></span></div>
                                            <div style="overflow: hidden;">
                                                <?php foreach($permission as $pm){ ?>
                                         
                                                    <span class="permit_name"><input type="checkbox" name="arr_permission[<?=$i;?>][<?=$pm->permission_code?>]"    <?php echo (isset($right_pm[$pm->permission_code])&&$right_pm[$pm->permission_code]==1)?'checked="true"':''; ?> value="1"> <?=$pm->permission_name?></span>
                                                <?php } ?>
                                            </div> 
                                        <?php   $i++;} ?>
                                            <script>
                                                 total_num = '<?php echo $i; ?>';
                                             </script>
                                    </div>
                                </td>
                            </tr>
                        <?php
                                $k=1-$k;
                              
                            } 
                        ?>  
                    </table>
                </td>
            </tr>
        </table>
    <?=form_close();?>
</div>